package com.puppet.building182.controller;

import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.puppet.building182.service.impl.AiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
public class AiController {
    @Autowired
    private AiService aiService;

    @Value("${spring.ai.dashscope.api-key}")
    private String api_Key;

    @Value("${spring.ai.dashscope.agent.app-id}")
    private String app_id;

    @GetMapping("/test1/{message}")
    public String test1(@PathVariable("message") String message) throws
            NoApiKeyException, InputRequiredException {
        //方案2：

        return aiService.call(message);
    }
    @GetMapping(value = "/call/{message}",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> call(@PathVariable("message") String message) throws
    NoApiKeyException, InputRequiredException {
        return aiService.callString(message);
    }
}

